package com.hdax.dmw.user.api;

import com.hdax.dmw.dtos.user.LoginDto;
import com.hdax.dmw.user.service.DmUserService;
import com.hdax.dmw.utils.Result;
import com.hdax.dmw.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping(path = "/user")
public class LoginApi {

    @Autowired
    private DmUserService userService;


    @PostMapping(path = "/refreshToken")
    public Result<LoginDto> refreshToken(HttpServletRequest request){
        String md5 = request.getHeader("md5");
        return userService.refreshToken(md5);
    }



    @PostMapping(path = "/login")
    public Result<LoginDto> login(
            @RequestBody Map<String,String> params
    ){
        String phone = params.get("phone");
        String password = params.get("password");
        return userService.login(phone, password);
    }
}
